package com.wq.myspring.aware;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @PackageName: com.wq.myspring.aware
 * @ClassName MyAware
 * @Description: TODO
 * @Author Wenqiang
 * @Date 2021/07/17 23:55
 * @Version V1.0
 */
@Component
public class MyAware implements ApplicationContextAware, BeanNameAware {

	private String myName;

	private ApplicationContext myContext;

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		this.myContext = applicationContext;
	}

	@Override
	public void setBeanName(String name) {
		this.myName = name;
	}

	public void option() {
		System.out.println("====" + myName);
		String[] beanDefinitionNames = myContext.getBeanDefinitionNames();
		Arrays.stream(beanDefinitionNames).forEach(System.out::println);
	}


}
